package com.java110.mall.cart.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.mall.cart.bmo.storeOrderCartUp.IDeleteStoreOrderCartUpBMO;
import com.java110.mall.cart.bmo.storeOrderCartUp.IGetStoreOrderCartUpBMO;
import com.java110.mall.cart.bmo.storeOrderCartUp.ISaveStoreOrderCartUpBMO;
import com.java110.mall.cart.bmo.storeOrderCartUp.IUpdateStoreOrderCartUpBMO;
import com.java110.dto.storeOrder.StoreOrderCartUpDto;
import com.java110.po.storeOrder.StoreOrderCartUpPo;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/storeOrderCartUp")
public class StoreOrderCartUpApi {

    @Autowired
    private ISaveStoreOrderCartUpBMO saveStoreOrderCartUpBMOImpl;
    @Autowired
    private IUpdateStoreOrderCartUpBMO updateStoreOrderCartUpBMOImpl;
    @Autowired
    private IDeleteStoreOrderCartUpBMO deleteStoreOrderCartUpBMOImpl;

    @Autowired
    private IGetStoreOrderCartUpBMO getStoreOrderCartUpBMOImpl;

    /**
     * 微信保存消息模板
     * @serviceCode /storeOrderCartUp/saveStoreOrderCartUp
     * @path /app/storeOrderCartUp/saveStoreOrderCartUp
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/saveStoreOrderCartUp", method = RequestMethod.POST)
    public ResponseEntity<String> saveStoreOrderCartUp(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "orderUpId", "请求报文中未包含orderUpId");
        Assert.hasKeyAndValue(reqJson, "productId", "请求报文中未包含productId");
        Assert.hasKeyAndValue(reqJson, "valueId", "请求报文中未包含valueId");
        Assert.hasKeyAndValue(reqJson, "storeId", "请求报文中未包含storeId");
        Assert.hasKeyAndValue(reqJson, "personId", "请求报文中未包含personId");
        Assert.hasKeyAndValue(reqJson, "cartNum", "请求报文中未包含cartNum");
        Assert.hasKeyAndValue(reqJson, "price", "请求报文中未包含price");
        Assert.hasKeyAndValue(reqJson, "prodName", "请求报文中未包含prodName");
        Assert.hasKeyAndValue(reqJson, "specName", "请求报文中未包含specName");
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");


        StoreOrderCartUpPo storeOrderCartUpPo = BeanConvertUtil.covertBean(reqJson, StoreOrderCartUpPo.class);
        return saveStoreOrderCartUpBMOImpl.save(storeOrderCartUpPo);
    }

    /**
     * 微信修改消息模板
     * @serviceCode /storeOrderCartUp/updateStoreOrderCartUp
     * @path /app/storeOrderCartUp/updateStoreOrderCartUp
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/updateStoreOrderCartUp", method = RequestMethod.POST)
    public ResponseEntity<String> updateStoreOrderCartUp(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "orderUpId", "请求报文中未包含orderUpId");
        Assert.hasKeyAndValue(reqJson, "productId", "请求报文中未包含productId");
        Assert.hasKeyAndValue(reqJson, "valueId", "请求报文中未包含valueId");
        Assert.hasKeyAndValue(reqJson, "storeId", "请求报文中未包含storeId");
        Assert.hasKeyAndValue(reqJson, "personId", "请求报文中未包含personId");
        Assert.hasKeyAndValue(reqJson, "cartNum", "请求报文中未包含cartNum");
        Assert.hasKeyAndValue(reqJson, "price", "请求报文中未包含price");
        Assert.hasKeyAndValue(reqJson, "prodName", "请求报文中未包含prodName");
        Assert.hasKeyAndValue(reqJson, "specName", "请求报文中未包含specName");
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");
        Assert.hasKeyAndValue(reqJson, "cartUpId", "cartUpId不能为空");


        StoreOrderCartUpPo storeOrderCartUpPo = BeanConvertUtil.covertBean(reqJson, StoreOrderCartUpPo.class);
        return updateStoreOrderCartUpBMOImpl.update(storeOrderCartUpPo);
    }

    /**
     * 微信删除消息模板
     * @serviceCode /storeOrderCartUp/deleteStoreOrderCartUp
     * @path /app/storeOrderCartUp/deleteStoreOrderCartUp
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/deleteStoreOrderCartUp", method = RequestMethod.POST)
    public ResponseEntity<String> deleteStoreOrderCartUp(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "shopId", "商铺ID不能为空");

        Assert.hasKeyAndValue(reqJson, "cartUpId", "cartUpId不能为空");


        StoreOrderCartUpPo storeOrderCartUpPo = BeanConvertUtil.covertBean(reqJson, StoreOrderCartUpPo.class);
        return deleteStoreOrderCartUpBMOImpl.delete(storeOrderCartUpPo);
    }

    /**
     * 微信删除消息模板
     * @serviceCode /storeOrderCartUp/queryStoreOrderCartUp
     * @path /app/storeOrderCartUp/queryStoreOrderCartUp
     * @param cartUpId 小区ID
     * @return
     */
    @RequestMapping(value = "/queryStoreOrderCartUp", method = RequestMethod.GET)
    public ResponseEntity<String> queryStoreOrderCartUp(@RequestParam(value = "productId" , required = false) String productId,
                                                      @RequestParam(value = "storeId" , required = false) String storeId,
                                                      @RequestParam(value = "orderUpId" , required = false) String orderUpId,
                                                      @RequestParam(value = "cartUpId" , required = false) String cartUpId,
                                                      @RequestParam(value = "personId" , required = false) String personId,
                                                      @RequestParam(value = "shopId" , required = false) String shopId,
                                                      @RequestParam(value = "page") int page,
                                                      @RequestParam(value = "row") int row) {
        StoreOrderCartUpDto storeOrderCartUpDto = new StoreOrderCartUpDto();
        storeOrderCartUpDto.setPage(page);
        storeOrderCartUpDto.setRow(row);
        storeOrderCartUpDto.setPersonId(productId);
        storeOrderCartUpDto.setShopId(shopId);
        storeOrderCartUpDto.setStoreId(storeId);
        storeOrderCartUpDto.setOrderUpId(orderUpId);
        storeOrderCartUpDto.setCartUpId(cartUpId);
        storeOrderCartUpDto.setPersonId(personId);

        return getStoreOrderCartUpBMOImpl.get(storeOrderCartUpDto);
    }
}
